package com.scu.gkvr_system_backend.controller;

import com.scu.gkvr_system_backend.service.MajorsService;
import com.scu.gkvr_system_backend.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @project gkvr_system_backend
 * @description 专业相关Controller层
 * @author qinyc
 * @date 2024/5/9 15:55:47
 * @version V1.0
 */
@RestController
@RequestMapping("/major")
@CrossOrigin
public class MajorsController {

    @Autowired
    private MajorsService majorsService;

    /**
     * 根据学位获取 全部专业信息 + 专业类型
     */
    @GetMapping("/list")
    public Result getListMajors(Integer page,String degreesName){
        Map<String,Object> map = majorsService.getListMajors(page,degreesName);
        return Result.success(map);
    }

    @GetMapping("/searchByName")
    public Result<Map<String, Object>> majorSearchByName(@RequestParam int page,
                                                         @RequestParam String majorName) {
        Map<String, Object> data = majorsService.SearchByName(page, majorName);
        if (data != null) {
            return Result.success(data);
        }
        return Result.fail("查询失败");
    }


}
